package com.itheima;

public class Student implements Comparable<Student> {
    private String name;
    private int age;
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return  "name='" + name + '\'' +
                ", age=" + age ;
    }
    @Override
    public int compareTo(Student o) {
        //按照学生年龄正序排序（当前学生年龄-被比较学生年龄）
        //this指的是当前对象
        return this.age - o.age;

        //按照学生年龄倒序排序（被比较学生年龄-当前学生年龄）
      //  return o.age - this.age;
    }
}
